package cn.venturesights.saber.mars.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@CrossOrigin
@RestController
public class InfoController {

    Logger logger = LoggerFactory.getLogger(getClass());

    @Value("${spring.application.name:}")
    String name;
    @Value("${custom.version:}")
    String version;
    @Value(("${custom.env:dev}"))
    String env;

    @GetMapping("/")
    public Map<String, Object> info() {
        logger.info("access info endpoint (/)");
        Map<String, Object> resp = new HashMap<>();
        resp.put("msg", String.format("welcome, it's %s api (%s)", name, version));
        resp.put("env", env);
        return resp;
    }

}
